package com.wjjun.viewmodel;

import android.databinding.ObservableArrayList;
import android.databinding.ObservableField;
import android.databinding.ObservableList;

import com.wjjun.basemvpvm.viewmodel.BaseItemViewModel;
import com.wjjun.basemvpvm.viewmodel.BaseViewModel;
import com.wjjun.customview.views.GlideImageLoader;
import com.youth.banner.BannerConfig;

/**
 * banner
 * Created by 67535 on 2018/4/29.
 */
public class BannerViewModel extends BaseViewModel {

    //数据源
    public final ObservableList<BannerItemViewModel> items = new ObservableArrayList<>();

    //宽高比例
    public final ObservableField<Float> scale = new ObservableField<>(0.52f);

    //图片加载器
    public final GlideImageLoader imageLoader = new GlideImageLoader();

    //是否自动播放
    public final ObservableField<Boolean> isAutoPlay = new ObservableField<>(false);

    //banner的样式,包括指示器和标题
    public final ObservableField<Integer> style = new ObservableField<>(BannerConfig.CIRCLE_INDICATOR);

    //指示器的位置
    public final ObservableField<Integer> indicatorGravity = new ObservableField<>(BannerConfig.CENTER);

    // 控制banner播放
    public final ObservableField<Boolean> start = new ObservableField<>();

    public void setItems(ObservableList<BannerItemViewModel> items) {
        this.items.clear();
        this.items.addAll(items);
    }

    /**
     * 设置是否自动播放
     *
     * @param isAutoPlay
     */
    public void setIsAutoPlay(boolean isAutoPlay) {
        this.isAutoPlay.set(isAutoPlay);
    }

    /**
     * 设置指示器在中间
     */
    public void setIndicatorCenter() {
        indicatorGravity.set(BannerConfig.CENTER);
    }

    /**
     * 设置指示器在右边
     */
    public void setIndicatorRight() {
        indicatorGravity.set(BannerConfig.RIGHT);
    }

    /**
     * 设置成数字指示器
     */
    public void setNumIndicator() {
        this.style.set(BannerConfig.NUM_INDICATOR);
    }

    /**
     * 设置成圆点指示器
     */
    public void setCircleIndicator() {
        style.set(BannerConfig.CIRCLE_INDICATOR);
    }

    /**
     * 控制banner的播放
     */
    public void setBannerStart(boolean isStart) {
        this.start.set(isStart);
    }
}

